package com.og.backingbean;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * @author Renaud DIANA
 *
 */
@Entity
@NamedQueries({@NamedQuery(name = "Company.findAll", query = "SELECT c FROM Company c ORDER BY c.idCompany ASC")})
public class Company implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id
	@Pattern(regexp="^[A-Z]{2}[-][A-Z]{1}[0-9]{3}$")	
	@Column(nullable = false, length = 50, updatable = false, unique = true)
	private String idCompany;
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String name;
	@Size(max = 50)
	@Column(length = 50)
	private String street;	
	private int number;
	@Size(max = 5)
	@Column(length = 5)
	private String box;
	private int zipCode;
	@Size(max = 30)
	@Column(length = 30)
	private String city;
	@Size(max = 30)
	@Column(length = 30)
	private String country;	
	private String comments;
	@OneToMany(mappedBy = "company", cascade = CascadeType.ALL)
	@JoinColumn(name = "company_idcompany")	
	private List<Person> listPersons;
	@ManyToMany(mappedBy = "listCompanies")
	private List<Contract> listContracts;
		
	/**
	 * default constructor
	 */
	public Company() {
		// TODO Auto-generated constructor stub
	}	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idCompany == null) ? 0 : idCompany.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Company other = (Company) obj;
		if (idCompany == null) {
			if (other.idCompany != null)
				return false;
		} else if (!idCompany.equals(other.idCompany))
			return false;
		return true;
	}

	public String getIdCompany() {
		return idCompany;
	}

	public void setIdCompany(String idCompany) {
		this.idCompany = idCompany;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public String getBox() {
		return box;
	}

	public void setBox(String box) {
		this.box = box;
	}

	public int getZipCode() {
		return zipCode;
	}

	public void setZipCode(int zipCode) {
		this.zipCode = zipCode;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public List<Person> getListPersons() {
		return listPersons;
	}

	public void setListPersons(List<Person> listPersons) {
		this.listPersons = listPersons;
	}

	public List<Contract> getListContracts() {
		return listContracts;
	}

	public void setListContracts(List<Contract> listContracts) {
		this.listContracts = listContracts;
	}	
}